from django.core.files.storage import FileSystemStorage
from Main.utils.FtpUtils import ftp_connect, upload_file


class ImageStorage(FileSystemStorage):
    from django.conf import settings

    def __init__(self, location=settings.MEDIA_ROOT, base_url=settings.MEDIA_ROOT):
        super(ImageStorage, self).__init__(location=location, base_url=base_url)

    def _save(self, name, content):
        ftp = ftp_connect("124.223.109.79", 21, "ftpuser", "HowardXue1211_")
        upload_file(ftp, '/var/ftp/images', content)
        ftp.close()
